package com.wellgoon.test.leetcode;

/**
 * @Author: Rocky
 * @Date: 2023/4/14
 */
public class BinaryTree {

    public static void main(String[] args) {
        BinaryTree bt = new BinaryTree();
        int[] nums = {80,70,75,100,90,85,120};
        TreeNode node = bt.helper(nums,0,nums.length-1);
        System.out.println(node);
    }

    private TreeNode root;

    public static TreeNode helper(int[] nums, int left, int right) {
        if (left > right) {
            return null;
        }
        // 总是选择中间位置左边的数字作为根节点
        int mid = (left + right) / 2;

        TreeNode root = new TreeNode(nums[mid]);
        root.left = helper(nums, left, mid - 1);
        root.right = helper(nums, mid + 1, right);
        return root;
    }


    private static class TreeNode {
        public int id;

        public TreeNode left;

        public TreeNode right;

        public TreeNode(int id) {
            this.id = id;
        }
    }
}


